﻿#ifndef _SQLFIELD_H_H_
#define _SQLFIELD_H_H_

#include "udatabase/sqlutility.h"
#include "udatabase/dll_cfg.h"
#include "kernel/Referenced.h"

namespace FD
{
	namespace Utility
	{
		namespace DB
		{
			class CSqlFieldPrivate;
			///<summary>
			///包含数据库某一表或者视图所有的字段
			///</summary>
			class FD_DB_Export CSqlField : public FD::Kernel::CReferenced
			{
			public:
				enum JASRequiredStatus { RS_Unknown = -1, RS_Optional = 0, RS_Required = 1 };
				///<summary>
				///默认构造函数
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				CSqlField();
				///<summary>
				///默认构造函数
				///</summary>
				///<param name="fieldName">字段名</param>
				///<returns></returns>
				CSqlField(const FD::Kernel::FdUnicodeString& fieldName);
				///<summary>
				///默认构造函数
				///</summary>
				///<param name="fieldName">字段名</param>
				///<param name="type">字段类型</param>
				///<returns></returns>
				CSqlField(const FD::Kernel::FdUnicodeString& fieldName, FD::Kernel::Variant::DataType type);
				///<summary>
				///拷贝构造函数
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlField对象</param>
				///<returns></returns>
				CSqlField(const CSqlField& other);
				///<summary>
				///赋值操作符的重载
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlField对象</param>
				///<returns></returns>
				FD::Utility::DB::CSqlField& operator=(const FD::Utility::DB::CSqlField& other);
				///<summary>
				///操作符==的重载
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlField对象</param>
				///<returns></returns>
				bool operator==(const FD::Utility::DB::CSqlField& other) const;
				///<summary>
				///操作符!=的重载
				///</summary>
				///<param name="other">FD::Utility::DB::CSqlField对象</param>
				///<returns></returns>
				inline bool operator!=(const FD::Utility::DB::CSqlField &other) const { return !operator==(other); }
				///<summary>
				///析构函数
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				~CSqlField();
				///<summary>
				///设置字段值
				///</summary>
				///<param name="value">字段值</param>
				///<returns></returns>
				void setValue(const FD::Kernel::Variant& value);
				///<summary>
				///获取字段值
				///</summary>
				///<param name=""></param>
				///<returns>字段值</returns>
				inline FD::Kernel::Variant value() const {return val;}
				///<summary>
				///设置字段名
				///</summary>
				///<param name="name">字段名</param>
				///<returns></returns>
				void setName(const FD::Kernel::FdUnicodeString& name);
				///<summary>
				///获取字段名
				///</summary>
				///<param name=""></param>
				///<returns>字段名</returns>
				const FD::Kernel::FdUnicodeString& name() const;
				///<summary>
				///字段是否为空
				///</summary>
				///<param name=""></param>
				///<returns>为空返回true,否则返回false</returns>
				bool isNull() const;
				///<summary>
				///设置字段是否只读
				///</summary>
				///<param name="readOnly">是否只读</param>
				///<returns></returns>
				void setReadOnly(bool readOnly);
				///<summary>
				///获取字段是否只读
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				bool isReadOnly() const;
				///<summary>
				///清除字段值并设置为空
				///</summary>
				///<param name=""></param>
				///<returns></returns>
				void clear();
				///<summary>
				///获取字段类型
				///</summary>
				///<param name=""></param>
				///<returns>字段类型</returns>
				FD::Kernel::Variant::DataType type() const;
				///<summary>
				///字段值是否是由数据库自动生成的
				///</summary>
				///<param name=""></param>
				///<returns>是自动生成的返回true,否则返回false</returns>
				bool isAutoValue() const;
				///<summary>
				///设置字段类型
				///</summary>
				///<param name="type">字段类型</param>
				///<returns></returns>
				void setType(FD::Kernel::Variant::DataType type);
				///<summary>
				///设置字段要求状态（有符号型还是无符号型）
				///</summary>
				///<param name="status">字段要求状态</param>
				///<returns></returns>
				void setRequiredStatus(FD::Utility::DB::CSqlField::JASRequiredStatus status);
				///<summary>
				///设置字段要求状态（有符号型还是无符号型）
				///</summary>
				///<param name="required">是否</param>
				///<returns></returns>
				void setRequired(bool required) {setRequiredStatus(required ? RS_Required : RS_Optional);}
				///<summary>
				///设置字段长度
				///</summary>
				///<param name="fieldLength">字段长度</param>
				///<returns></returns>
				void setLength(INT32 fieldLength);
				///<summary>
				///设置字段精度
				///</summary>
				///<param name="precision">字段精度</param>
				///<returns></returns>
				void setPrecision(INT32 precision);
				///<summary>
				///设置字段默认值
				///</summary>
				///<param name="value">字段默认值</param>
				///<returns></returns>
				void setDefaultValue(const FD::Kernel::Variant &value);
				///<summary>
				///设置字段的sql类型
				///</summary>
				///<param name="type">类型</param>
				///<returns></returns>
				void setSqlType(INT32 type);
				///<summary>
				///设置字段的生成状态
				///</summary>
				///<param name="gen">是否生成此字段</param>
				///<returns></returns>
				void setGenerated(bool gen);
				///<summary>
				///设置字段值是否是由数据库自动生成的
				///</summary>
				///<param name="autoVal">是否</param>
				///<returns></returns>
				void setAutoValue(bool autoVal);
				///<summary>
				///获取字段要求状态（有符号型还是无符号型）
				///</summary>
				///<param name="status"></param>
				///<returns>字段要求状态</returns>
				FD::Utility::DB::CSqlField::JASRequiredStatus RequiredStatus() const;
				///<summary>
				///获取字段长度
				///</summary>
				///<param name=""></param>
				///<returns>字段长度</returns>
				INT32 length() const;
				///<summary>
				///设置字段精度
				///</summary>
				///<param name=""></param>
				///<returns>字段精度</returns>
				INT32 precision() const;
				///<summary>
				///获取字段默认值
				///</summary>
				///<param name=""></param>
				///<returns>字段默认值</returns>
				FD::Kernel::Variant defaultValue() const;
				///<summary>
				///获取字段的生成状态
				///</summary>
				///<param name=""></param>
				///<returns>如果此字段能被生成返回true,否则返回false</returns>
				bool isGenerated() const;
				///<summary>
				///字段的FD::Kernel::Variant类型是否有效
				///</summary>
				///<param name=""></param>
				///<returns>有效返回true</returns>
				bool isValid() const;

			private:
				void detach();
				FD::Kernel::Variant	val;
				CSqlFieldPrivate *m_private;

			};

		} // namespace Database
	} 
} 

#endif //_SQLFIELD_H_H_

